from django.db import models

# Create your models here.
from django.db import models
from hashlib import md5
# Create your models here.
class User(models.Model):               #定义数据库
    u_user = models.CharField(max_length=20)
    u_password = models.CharField(max_length=100)
    u_perssions = models.CharField(max_length=20)
    u_username = models.CharField(max_length=20)
    u_email = models.EmailField(default='')
    u_tel = models.CharField(max_length=11)
    u_addr = models.CharField(max_length=100)

    def create(self, user, password, perssions, username, email, tel, add="comment"):
            self.u_user = user
            self.u_password = password
            self.u_username = username
            self.u_email = email
            self.u_tel = tel
            self.u_addr = add
            self.u_perssions = perssions
            self.save()
    @classmethod
    def findName(cls,username,password=''):
        name=User.objects.filter(u_user=username)
        if len(name)>=1:
            if password != '':
                password=name[0].password
                md = md5()
                md.update(password.encode())
                if md.hexdigest()==password:
                    return True
                else:
                    return False
            return False
        else:
            return True
    
    class Meta:

        db_table = 'user'
